Ext.onReady(function(){ 

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'under';

var addIDTypeStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=CertType',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad:true
}); 

var addSexTypeStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=SexType',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad:true
}); 

var addDegreeStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=DEGREE',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad:true
});

var addGradeStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=GRADE',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad:true
}); 

var addMstatusStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=Mstatus',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad:true
});


//客户基本信息
var addForm = new Ext.form.FormPanel({ 
id: 'addForm', 
title: '贷款信息', 
renderTo:"list",
height: 200, 
//样式 
bodyStyle: 'margin:5px;text-align:left;padding:5px 60px;', 
frame: true, 
xtype: 'filedset', 
labelWidth: 120, 
items: 
[ { xtype: 'fieldset', 
collapsible: true, 
autoHeight: true, 
autoWidth: true, 
items: 
[
	{layout:"column",
		items:[{
			columnWidth : .5, // 该列有整行中所占百分比
		           layout : "form",
		           items : [{
		        	   xtype: 'textfield', 
		       		id:'custNo',
		       		name: 'custNo', 
		       		fieldLabel: '客户号', 
		       		readOnly:true,
		       		width: 200
		}
		]},{
			columnWidth : .5, // 该列有整行中所占百分比
		           layout : "form",
		           items : [{
		        	   xtype: 'textfield', 
		        		id:'loanCount',
		        		name: 'loanCount', 
		        		fieldLabel: '笔数', 
		        		width: 200   		
		}
		]} 
]},	
	
{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
	        	xtype: 'textfield', 
	       		id:'loanBankSum1',
	       		name: 'loanBankSum1', 
	       		fieldLabel: '贷款法人机构数', 
	       		width: 200   	
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
        	   xtype: 'textfield', 
	       		id:'loanBankSum2',
	       		name: 'loanBankSum2', 
	       		fieldLabel: '贷款机构数', 
	       		width: 200  
}
]} 
]},{
layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
        	   xtype: 'textfield', 
	       		id:'loanContractSum',
	       		name: 'loanContractSum', 
	       		fieldLabel: '贷款合同金额（元）', 
	       		regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
				regexText:'精确到小数点后两位！' , 
	       		width: 200 
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
        	   xtype: 'textfield', 
	       		id:'loanBalance',
	       		name: 'loanBalance', 
	       		fieldLabel: '最高贷款余额（元）', 
	       		regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
				regexText:'精确到小数点后两位！' , 
	       		width: 200 
}
]} 
]},

{
	layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	        	   xtype: 'textfield', 
		       		id:'loanSum',
		       		name: 'loanSum', 
		       		fieldLabel: '贷款余额（元）', 
		       		regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
					regexText:'精确到小数点后两位！' ,  
		       		width: 200 
	}
	]},{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	        	   xtype: 'textfield', 
		       		id:'dueSum',
		       		name: 'dueSum', 
		       		fieldLabel: '当期逾期总额（元）',
		       		regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
					regexText:'精确到小数点后两位！' , 
		       		width: 200 
	}
	]} 
	]},

] 
}],
buttonAlign:'right',
buttons: 
[  
{ text: '保存', handler: editFunction } , 
{ text: '下一步', handler: editFunctionAndNext } 
] 
});


//表单加载数据
addForm.form.load({  
    waitMsg : '正在加载数据请稍后',
    waitTitle : '提示',
    url : 'customer/getIndOloan.do', 
    method:'post',
    success:function(form,action){
    	
    },  
    failure:function(form,action){
     Ext.Msg.alert('提示','数据加载失败');  
    }  
});

function editFunction(){

	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
			url : 'customer/editIndOloan.do', 
			method : 'post', 
			success : function() {
				Ext.Msg.alert('提示', '保存成功！'); 
			}, 
			failure : function() { 
				Ext.Msg.alert('提示', '保存失败！'); 
			} 
		}); 
	}
	
}

function editFunctionAndNext(){
	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
			url : 'customer/editIndOloan.do', 
			method : 'post', 
			success : function() {
				Ext.Msg.confirm("Confirm",'保存成功，是否继续添加担保信息',function(bool){
					if(bool=='yes'){
						window.location.href = "view/customer/Customer_IndOguarantee.jsp";
						return true;
					}
					else{
						return false;	
					}
				}); 
				//alert("成功");
				
			}, 
			failure : function() { 
				Ext.Msg.alert('提示', '保存失败！'); 
			} 
		}); 
	}
}
       
}); 